//
//  DialectShareViewController.m
//  DialectShare
//
//  Created by timmy zhong on 3/29/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "DialectShareViewController.h"

#import "AroundViewController.h"
#import "YuXiViewController.h"
#import "FeedsViewController.h"
#import "InfoViewController.h"
#import "SettingsViewController.h"
#import "LoginViewController.h"
#import "User.h"

@interface DialectShareViewController ()
- (void)loadControllers;
@end

@implementation DialectShareViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewDidAppear:(BOOL)animated
{
    if (![User current]) {
        LoginViewController *loginController = [[LoginViewController alloc] init];
        [self presentViewController:loginController animated:NO completion:nil];
        [loginController release];
        return;
    }
    
    [self loadControllers];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)loadControllers
{
    AroundViewController *around = [[AroundViewController alloc] init];
    UINavigationController *aroundNav = [[UINavigationController alloc] initWithRootViewController:around];
    aroundNav.navigationBar.barStyle = UIBarStyleBlackOpaque;
    around.title = @"周边";  
    UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTitle:@"周边" image:[UIImage imageNamed:@"zhou-bian.png"] tag:1];
    aroundNav.tabBarItem = tabBarItem;
    [tabBarItem release];
    [around release];
    
    YuXiViewController *yuxi = [[YuXiViewController alloc] initWithNibName:@"YuXiViewController" bundle:nil];
    UINavigationController *yuxiNav = [[UINavigationController alloc] initWithRootViewController:yuxi];
    yuxiNav.navigationBar.barStyle = UIBarStyleBlackOpaque;
    yuxi.title = @"语系";
    yuxiNav.tabBarItem.title = @"语系";
    [yuxi release];
    
    FeedsViewController *feed = [[FeedsViewController alloc] init];
    UINavigationController *feedNav = [[UINavigationController alloc] initWithRootViewController:feed];
    feedNav.navigationBar.barStyle = UIBarStyleBlackOpaque;
    feed.title = @"动态";
    feedNav.tabBarItem.title = @"动态";
    [feed release];
    
    InfoViewController *info = [[InfoViewController alloc] initWithNibName:@"InfoViewController" bundle:nil];
    UINavigationController *infoNav = [[UINavigationController alloc] initWithRootViewController:info];
    infoNav.navigationBar.barStyle = UIBarStyleBlackOpaque;
    info.title = @"我的";
    infoNav.tabBarItem.title = @"我的";
    [info release];
    
    SettingsViewController *settings = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
    UINavigationController *settingsNav = [[UINavigationController alloc] initWithRootViewController:settings];
    settingsNav.navigationBar.barStyle = UIBarStyleBlackOpaque;
    settings.title = @"更多";
    settingsNav.tabBarItem.title = @"更多";
    [settings release];
    
    UITabBarController *tabbarController = [[UITabBarController alloc] init];
    [tabbarController setViewControllers:[NSArray arrayWithObjects:aroundNav, yuxiNav, feedNav, infoNav, settingsNav, nil]];
    [yuxiNav release];
    [feedNav release];
    [infoNav release];
    [settingsNav release];
    [aroundNav release];
    
    [self presentViewController:tabbarController animated:NO completion:nil];

}

@end
